//
//  SPHorizontalButton.m
//  Sport
//
//  Created by Cass on 2017/11/14.
//  Copyright © 2017年 Cass. All rights reserved.
//

#import "SPHorizontalButton.h"

@implementation SPHorizontalButton
- (void)layoutSubviews{
    [super layoutSubviews];
    //1.获取titleLabel的frame
    CGRect titleLabelFrame = self.titleLabel.frame;
    //2.修改titleLabel的frame
    titleLabelFrame.origin.x = (self.frame.size.width - self.titleLabel.frame.size.width - self.imageView.frame.size.width) * 0.5;
    //3.重新赋值
    self.titleLabel.frame = titleLabelFrame;
    
    //1.获取imageView的frame
    CGRect imgFrame = self.imageView.frame;
    //2.修改imgView的frame
    imgFrame.origin.x = titleLabelFrame.origin.x + titleLabelFrame.size.width + 5;
    //3.重新赋值
    self.imageView.frame = imgFrame;
}

- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event{
    CGRect bounds = self.bounds;
    CGFloat widthDelta = MAX(44 - bounds.size.width, 0);
    CGFloat heightDelta = MAX(44 - bounds.size.height, 0);
    // CGRectInset：以rect中心，根据dx，dy来缩放，负值表示放大。
    bounds = CGRectInset(bounds, -0.5*widthDelta, -0.5*heightDelta);
    return CGRectContainsPoint(bounds, point);
}

@end
